/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iteracon.stack;

import iteracon.stack.iterator.Pulley;
import iteracon.stack.iterator.StkIter;
import java.util.Iterator;
import iteracon.IteraconBase;
import java.util.List;
import java.util.ListIterator;

/**
 * stack
 * @author martin
 */
public final class PushStk<T> extends StkBase<T>{
  private final Stk _back;
  private final T _data;
  /**
   * constructor
   * @param s as stack
   * @param t as element
   */
  private PushStk(final Stk<T> s,final T t){
    _back= s;
    _data = t;
  }
  /**
   * make new stack from nothing
   * @param <T> as type
   * @param t as element
   * @return new stack
   */
  public static<T> Stk<T> newStk(final T t){
    Stk<T> tmp = EmptyStk.makeStk();
    return tmp.push(t);
  }
  
  /**
   * add to given stack
   * @param <T> as type
   * @param s as stack
   * @param t as element
   * @return new stack
   */
  public static<T> Stk<T> addTo(final Stk<T> s, final T t){
    if (s==null)
      throw new NullPointerException("witch stack ?");
    return new PushStk(s,t);
  }
  
  //stk
  @Override
  public T top() {
    return _data;
  }

  @Override
  public Stk<T> pop() {
    return _back;
  }
  
  @Override
  public int size() {
    Stk tmp = this;
    int cnt = 1;
    while (tmp!=null){
      tmp = pop();
      cnt++;
    }
    return cnt;
  }

  



  

}
